//
//  WKMineHeaderView.m
//  WKMaybell
//
//  Created by 何文虎 on 2019/1/2.
//  Copyright © 2019 何文虎. All rights reserved.
//

#import "WKMineHeaderView.h"

@interface WKMineUserIconView : UIView

@property(nonatomic,strong)UIImageView *iconImgView;
@property(nonatomic,strong)UILabel *titleLb;
@property(nonatomic,strong)UIButton *btn;
@end

@implementation WKMineUserIconView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        [self setup];
    }
    return self;
}

- (void)setup{
    
    self.backgroundColor = [UIColor whiteColor];
    self.iconImgView = [[UIImageView alloc]init];
    [self addSubview:self.iconImgView];
    [self.iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(15);
        make.size.mas_equalTo(CGSizeMake(35, 35));
        make.centerX.mas_equalTo(self.mas_centerX);
    }];
    _iconImgView.layer.masksToBounds = YES;
    _iconImgView.layer.cornerRadius = 35/2;
    
    self.titleLb = [[UILabel alloc]init];
    [self addSubview:self.titleLb];
    [self.titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-15);
        make.left.right.with.mas_equalTo(0);
        make.height.mas_equalTo(12);
    }];
    _titleLb.font = PFSC_MediumFont(12);
    _titleLb.textColor = UIColorFromHex(0x3C3C3C);
    _titleLb.textAlignment = NSTextAlignmentCenter;
    
    _iconImgView.backgroundColor = [UIColor magentaColor];
    
}

@end


@interface WKMineHeaderView ()
@property(nonatomic,strong)UIView *contentView;
@property(nonatomic,strong)UIImageView *headerImageView;
@property(nonatomic,strong)UIView *userView;
@property(nonatomic,strong)UILabel *userNameLb;
@property(nonatomic,strong)UIButton *setingBtn;
@property(nonatomic,strong)UIButton *remindBtn;
@property(nonatomic,strong)UIImageView *sexImgView;
@property(nonatomic,strong)UILabel *ageLb;
@property(nonatomic,strong)UILabel *gzNumLb;
@property(nonatomic,strong)UILabel *fancLb;
@property(nonatomic,strong)UILabel *dbNumLb;
@end

@implementation WKMineHeaderView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self == [super initWithFrame:frame]) {
        self.contentView = [[UIView alloc]initWithFrame:frame];
        [self addSubview:self.contentView];
        [self layoutMineHeaderView];
    }
    return self;
}

- (void)layoutMineHeaderView{
    
    UIImageView *bgImgView = [[UIImageView alloc]init];
    [self.contentView addSubview:bgImgView];
    [bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(123+NavBarHeight);
        
    }];
    
    //x消息
    [self.contentView addSubview:self.remindBtn];
    [self.remindBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(StatusBarHeight+20);
        make.left.mas_equalTo(12);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
    }];
    self.remindBtn.backgroundColor = [UIColor whiteColor];
    [self.remindBtn addTarget:self action:@selector(navibarAction:) forControlEvents:UIControlEventTouchUpInside];
    self.remindBtn.tag = 900;
    
    //设置
    [self.contentView addSubview:self.setingBtn];
    [self.setingBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(StatusBarHeight+20);
        make.right.mas_equalTo(-12);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
    }];
    self.setingBtn.backgroundColor = [UIColor whiteColor];
    [self.setingBtn addTarget:self action:@selector(navibarAction:) forControlEvents:UIControlEventTouchUpInside];
    self.setingBtn.tag = 901;
    
    
    [self.contentView addSubview:self.userView];
    [self.userView mas_makeConstraints:^(MASConstraintMaker *make) {
         make.top.mas_equalTo(NavBarHeight+28);
        make.left.mas_equalTo(20);
        make.right.mas_equalTo(-20);
        make.height.mas_equalTo(162);
    }];

    _userView.layer.cornerRadius = 5;
    _userView.layer.masksToBounds = YES;

    [self.contentView addSubview:self.headerImageView];
    [self.headerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
        make.top.mas_equalTo(NavBarHeight-2);
        make.centerX.mas_equalTo(self.contentView.mas_centerX);
    }];

    [self.userView addSubview:self.userNameLb];
    [self.userNameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.headerImageView.mas_bottom).offset(17);
        make.height.mas_equalTo(14);
        make.centerX.mas_equalTo(self.userView.mas_centerX);
    }];
    
    [self.userView addSubview:self.sexImgView];
    [self.sexImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(14);
        make.height.mas_equalTo(14);
    }];
    
    _sexImgView.layer.cornerRadius = 7;
    _sexImgView.layer.masksToBounds = YES;

    [self.userView addSubview:self.ageLb];
    [self.ageLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.userNameLb.mas_bottom).offset(8);
        make.left.mas_equalTo(5);
        make.right.mas_equalTo(-5);
        make.height.mas_equalTo(11);
        make.centerX.mas_equalTo(self.userView.mas_centerX);
    }];

    CGFloat bumberWidth = (ScreenWidth - 40)/3;


    [self.userView addSubview:self.gzNumLb];
    [self.gzNumLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.ageLb.mas_bottom).offset(20);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);

    }];
    
    UILabel *gztitleLb = [[UILabel alloc]init];
    gztitleLb.text = @"关注";
    gztitleLb.textColor = UIColorFromHex(0x979797);
    gztitleLb.font = PFSC_MediumFont(12);
    gztitleLb.textAlignment = NSTextAlignmentCenter;
    [self.userView addSubview:gztitleLb];
    [gztitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzNumLb.mas_bottom).offset(10);
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);
    }];


    [self.userView addSubview:self.fancLb];
    [self.fancLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzNumLb.mas_top);
        make.left.mas_equalTo(self.gzNumLb.mas_right);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);

    }];
    
    UIImageView *line1 = [[UIImageView alloc]init];
    line1.backgroundColor = LINEBACK_COLOR;
    [self.userView addSubview:line1];
    [line1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzNumLb.mas_top).offset(8);
        make.left.mas_equalTo(self.gzNumLb.mas_right);
        make.width.mas_equalTo(1);
        make.bottom.mas_equalTo(gztitleLb.mas_bottom).offset(-8);
        
    }];
    
    UILabel *fanctitleLb = [[UILabel alloc]init];
    fanctitleLb.text = @"粉丝";
    fanctitleLb.textColor = UIColorFromHex(0x979797);
    fanctitleLb.font = PFSC_MediumFont(12);
    fanctitleLb.textAlignment = NSTextAlignmentCenter;
    [self.userView addSubview:fanctitleLb];
    [fanctitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(gztitleLb.mas_top);
        make.left.mas_equalTo(gztitleLb.mas_right);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);
    }];
    
    
    UIImageView *line2 = [[UIImageView alloc]init];
    line2.backgroundColor = LINEBACK_COLOR;
    [self.userView addSubview:line2];
    [line2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.fancLb.mas_top).offset(8);
        make.left.mas_equalTo(self.fancLb.mas_right);
        make.width.mas_equalTo(1);
        make.bottom.mas_equalTo(fanctitleLb.mas_bottom).offset(-8);
        
    }];
    

    [self.userView addSubview:self.dbNumLb];
    [self.dbNumLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.gzNumLb.mas_top);
        make.left.mas_equalTo(self.fancLb.mas_right);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);
    }];
    
    UILabel *dbtitleLb = [[UILabel alloc]init];
    dbtitleLb.text = @"痘币";
    dbtitleLb.textColor = UIColorFromHex(0x979797);
    dbtitleLb.font = PFSC_MediumFont(12);
    dbtitleLb.textAlignment = NSTextAlignmentCenter;
    [self.userView addSubview:dbtitleLb];
    [dbtitleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(gztitleLb.mas_top);
        make.left.mas_equalTo(fanctitleLb.mas_right);
        make.width.mas_equalTo(bumberWidth);
        make.height.mas_equalTo(14);
    }];

    NSArray *titleArr = @[@"我的说圈",@"我的评论",@"我的收藏",@"我的打赏"];
    CGFloat iconView_Width = ScreenWidth/4;
    for (int i = 0; i<titleArr.count; i++) {
        WKMineUserIconView *iconView = [[WKMineUserIconView alloc]initWithFrame:CGRectMake(iconView_Width*i,NavBarHeight+190+11, iconView_Width, 88)];

        iconView.titleLb.text = titleArr[i];
        [self.contentView addSubview:iconView];
    }
    
    
    self.contentView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    bgImgView.backgroundColor = BACK_COLOR;
    self.userView.backgroundColor = [UIColor whiteColor];
    
    [_headerImageView sd_setImageWithURL:[NSURL URLWithString:@"http://b-ssl.duitang.com/uploads/item/201410/04/20141004162939_VERQc.jpeg"]];
    _headerImageView.contentMode = UIViewContentModeScaleAspectFill;
    _headerImageView.layer.masksToBounds = YES;
    _headerImageView.layer.cornerRadius = 60/2;
    
    _sexImgView.backgroundColor = [UIColor redColor];
    NSString *name = @"鲁班七号太空漫游";
    CGFloat nameWidth = [name boundingRectWithSize:CGSizeMake(200, 14) font:PFSC_RegularFont(15) lineSpacing:5].width+10;
    _userNameLb.text = name;
    [_userNameLb mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(nameWidth);
    }];
    
    [_sexImgView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.userNameLb.mas_right);
        make.centerY.mas_equalTo(self.userNameLb.mas_centerY);
    }];
    
    _ageLb.text = @"北京市 | 25岁 | 女";
    
    _gzNumLb.text = @"16";
    _fancLb.text = @"124";
    _dbNumLb.text = @"268";
    
    
}

- (void)navibarAction:(UIButton*)sender{
    if (self.navBlock) {
        self.navBlock(sender.tag-900);
    }
}

- (UIImageView*)headerImageView{
    if (!_headerImageView) {
        _headerImageView = [[UIImageView alloc]init];
    }
    return _headerImageView;
}

- (UIImageView*)sexImgView{
    if (!_sexImgView) {
        _sexImgView = [[UIImageView alloc]init];
    }
    return _sexImgView;
}

- (UIView*)userView{
    if (!_userView) {
        _userView = [[UIView alloc]init];
    }
    return _userView;
}

- (UIButton*)setingBtn{
    if (!_setingBtn) {
        _setingBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _setingBtn;
}

- (UIButton*)remindBtn{
    if (!_remindBtn) {
        _remindBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    }
    return _remindBtn;
}

- (UILabel*)userNameLb{
    if (!_userNameLb) {
        _userNameLb = [[UILabel alloc]init];
        _userNameLb.font = PFSC_RegularFont(15);
        _userNameLb.textColor = UIColorFromHex(0x3C3C3C);
        _userNameLb.textAlignment = NSTextAlignmentCenter;
    }
    return _userNameLb;
}

- (UILabel*)ageLb{
    if (!_ageLb) {
        _ageLb = [[UILabel alloc]init];
        _ageLb.textAlignment = NSTextAlignmentCenter;
        _ageLb.font = PFSC_MediumFont(11);
        _ageLb.textColor = UIColorFromHex(0x3C3C3C);
    }
    return _ageLb;
}

- (UILabel*)gzNumLb{
    if (!_gzNumLb) {
        _gzNumLb = [[UILabel alloc]init];
        _gzNumLb.textAlignment = NSTextAlignmentCenter;
        _gzNumLb.font = PFSC_BoldFont(15);
        _gzNumLb.textColor = UIColorFromHex(0x3C3C3C);
    }
    return _gzNumLb;
}

- (UILabel*)fancLb{
    if (!_fancLb) {
        _fancLb = [[UILabel alloc]init];
        _fancLb.textAlignment = NSTextAlignmentCenter;
        _fancLb.font = PFSC_BoldFont(15);
        _fancLb.textColor = UIColorFromHex(0x3C3C3C);
    }
    return _fancLb;
}


- (UILabel*)dbNumLb{
    if (!_dbNumLb) {
        _dbNumLb = [[UILabel alloc]init];
        _dbNumLb.textAlignment = NSTextAlignmentCenter;
        _dbNumLb.font = PFSC_BoldFont(15);
        _dbNumLb.textColor = UIColorFromHex(0x3C3C3C);
    }
    return _dbNumLb;
}

@end
